# delimit ;
clear ;
cd "replication" ;
set more off ; 

* *************************************************************************** ;
* load data 
* *************************************************************************** ;

use "./data/midline.dta", clear ; 

****************************************************************************** ;
* generate randomization strata and wave-class variable
****************************************************************************** ;

egen strata = group(wave neighborhood female mfi) ;
egen waveclass = group(wave class) ;

****************************************************************************** ;
* label variables for the LaTeX tables
****************************************************************************** ;

label var healthonly "HEE" ;
label var healthandpay "HEEC" ;

label var midline_knowledge1 "\shortstack[l]{Knows\\washing\\ hands\\with sand\\is not as\\effective\\as soap}"  ; 
label var midline_knowledge2 "\shortstack[l]{Knows\\water\\strained\\with\\cloth\\is not\\safe\\to drink}" ; 
label var midline_knowledge3 "\shortstack[l]{Knows\\iron\\deficiency\\in pregnancy\\is avoided\\through\\diet}" ;
label var midline_knowledge4 "\shortstack[l]{Knows\\sonography\\not\\essential\\in every\\pre-natal\\check-up}" ; 
label var midline_knowledge5 "\shortstack[l]{Knows\\child on\\exclusive\\breastfeeding\\can't be\\given water}" ;
label var midline_knowledge6 "\shortstack[l]{Knows\\having a\\trained\\midwife\\is im-\\portant}" ;
label var midline_knowledge7 "\shortstack[l]{Knows\\AIDS\\ is not\\ curable}" ;
label var midline_knowledge8 "\shortstack[l]{Knows\\syphilis\\can be\\contracted\\through\\unpro-\\tected sex}" ;

* *******************************************************************************
* regressions
* ******************************************************************************* ;

* outcomes are dummies for correct answers to each question ;

est drop _all ;

foreach var of varlist midline_knowledge1-midline_knowledge8 { ; 

	areg `var' healthonly healthandpay, a(strata) robust ;
	qui est sto `var'; 
	
	test healthonly = healthandpay ; 
	estadd local titlerow = "" ; 
	estadd scalar fstat = r(F): `var' ; 
	estadd scalar pval = r(p): `var' ; 

	summarize `var' if control == 1 & e(sample) == 1;
	estadd scalar cmean = r(mean): `var' ; 
	estadd scalar csd = r(sd): `var' ;

} ;

esttab * using "./output/appendix-table-midline-knowledge-by-question.tex",
	replace
	drop(_cons) 
	cells(b(label() star fmt(%9.3f %9.3f)) se(par)) 
	star(* 0.10 ** 0.05 *** 0.01) 
	stats(titlerow fstat pval cmean csd N, fmt(%9s %9.3f %9.3f %9.3f %9.3f %9.0f) labels("\(F\)-test, HEE = HEEC" "$\qquad$ \(F\)-statistic" "$\qquad$ \(p\)-value" "Control Mean" "Control SD" "N"))
	prehead(\begin{table}\centering \normalsize `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"'
		\captionsetup{justification=centering} 
		\caption{\normalsize Effects on Short-Term Health Knowledge, Individual Questions}
		\label{table-midline-knowledge-by-question}
		\begin{tabular*}{\hsize}{p{3.8cm}p{1.6cm}p{1.6cm}p{1.6cm}p{1.6cm}p{1.6cm}p{1.6cm}p{1.6cm}p{1.6cm}}
		\toprule)
	legend label  booktabs  collabels( , none)
	mgroups(
	"Cleanliness and Hygiene"
	"Midwives, Maternal \& Child Health" 
	"Condoms, AIDS, Syphilis" 
	, pattern(1 0 1 0 0 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
	postfoot(`"\bottomrule"'  \end{tabular*} \captionsetup{justification=justified, width=\hsize} 
		\caption*{\scriptsize \textit{Notes:} 
		Outcomes are from a health knowledge test three weeks after the final film screening.
		The dependent variables are all dummies for 
		whether the respondent answered the given knowledge question correctly. 
		\textit{HEE} is a dummy for assignment to only health entertainment-education. 
		\textit{HEEC} is a dummy for assignment to health entertainment-education with cash incentives for test performance. 
		Robust standard errors.
		All regressions include dummies for randomization strata, where strata are defined by gender, neighborhood, and microfinance client status.
		***\$\,p < 0.01$, **\$\,p < 0.05$, *\$\,p<0.10$.
		}
		\end{table}) ;
		
exit ;
